Java stored procedure

A Java stored procedure is a procedure that is written in Java instead of 3GL languages like PL/SQL and stored in the Oracle database. They are executed by the JVM. For this, the database memory space is used.[1] It is sometimes wrongly abbreviated as JSP.

A stored procedure is a program that is kept and executed within a database server. The procedure is called from a Java class using a special syntax. When the procedure is called, its name and any relevant parameters are sent over the JDBC connection to the DBMS, which executes the procedure and returns the results (if applicable) via the connection.

Stored procedures share many advantages with application servers based on EJBs or CORBA. The principal difference is that stored procedures are bundled free with many popular DBMSs, while application servers are frequently expensive, take time to administer and code for, and require more complex client software.

Since stored procedures run in the DBMS itself, they can help to reduce latency in applications. Rather than executing four or five SQL statements in a Java application, executing one stored procedure performs all the operations on the server side. A simple reduction in network requests can dramatically improve performance.

The following list summarizes the advantages of stored procedures:

The main disadvantage to using stored procedures is that it can place important code outside of the reach of your source control system.

Stored procedure parameter properties

Procedure limitations and notes

A stored procedure may not create views, defaults, rules, triggers, or procedures or issue the use statement (a "system stored procedure" is necessary if a stored procedure is to operate within the context of the database it is called from). Tables may be created in stored procedures: typically, temporary tables are used for storing intermediate results or as work tables; these temporary tables are dropped at procedure termination. A table cannot be created, dropped, and re-created with the same name in a single procedure.

Stored procedures are parsed in a single pass and will not resolve forward or backward references. For example, when defining a stored procedure that references a temporary table, either the stored procedure must create the temporary table prior to referencing it, or the temporary table must exist at the time the stored procedure is created.

Stored procedures are reusable, but not reentrant. They can be recursive.

Stored procedures may reference objects in other databases and call other procedures to a nesting depth of 16.

References

  1. ^ A Java Stored Procedure is a procedure coded in Java (as opposed to PL/SQL) and stored in the Oracle database. Java Stored procedures are executed by the database JVM in database memory space.